package worldinruin.gui.imp;

import java.util.ArrayList;

import javax.swing.JPanel;

import worldinruin.core.IBuilding;
import worldinruin.core.ITile;
import worldinruin.core.ITroop;
import worldinruin.core.imp.battle.Battle;
import worldinruin.gui.imp.gameview.BattleCommandPanel;
import worldinruin.gui.imp.gameview.BattleMainPanel;
import worldinruin.gui.imp.gameview.BuildPanel;
import worldinruin.gui.imp.gameview.DivideTroopsPanel;
import worldinruin.gui.imp.gameview.EmptyTileInfoPanel;
import worldinruin.gui.imp.gameview.SelectedBuildingPanel;
import worldinruin.gui.imp.gameview.SelectedTroopsPanel;
import worldinruin.gui.imp.gameview.TrainSoldiersPanel;
import worldinruin.gui.imp.gameview.TroopPanel;
import worldinruin.resources.Panels;

public class PanelFactory {
	
	private DivideTroopsPanel divideTroopsPanel;
	private EmptyTileInfoPanel emptyTileInfoPanel;
	private SelectedBuildingPanel selectedBuildingPanel;
	private SelectedTroopsPanel troopsSelectedPanel;
	private BuildPanel buildPanel;
	private BattleMainPanel battleMainPanel;
	private BattleCommandPanel battleCommandPanel;
	
	/**
	 * Creates a panel.
	 * @param panel Panel to create.
	 * @return Panel specified.
	 */
	public JPanel createPanel(Panels panel) {
		if (panel == Panels.TRAINSOLDIERSPANEL) {
			return new TrainSoldiersPanel();
		} else if (panel == Panels.BATTLECOMMANDPANEL) {
			if (battleCommandPanel == null) {
				battleCommandPanel = new BattleCommandPanel();
			}
			return battleCommandPanel;
		}
		
		return null;
	}
	
	/**
	 * Creates a new panel.
	 * @param panel Panel to create.
	 * @param arg Updating information.
	 * @return New panel.
	 */
	public JPanel createPanel(Panels panel, Object arg) {
		if (panel == Panels.BATTLEMAINPANEL) {
			if (battleMainPanel == null) {
				System.out.println("batmain");
				System.out.println(arg);
				battleMainPanel = new BattleMainPanel((Battle) arg);
			}
			
			return battleMainPanel;
		} else if (panel == (Panels.DIVIDETROOPSPANEL)) {
			if (divideTroopsPanel == null ) {
				divideTroopsPanel = new DivideTroopsPanel((ITroop) arg);
			}
			return divideTroopsPanel;
			
		} else if (panel ==(Panels.EMPTYTILEINFOPANEL)) {
			if (emptyTileInfoPanel == null) {
				emptyTileInfoPanel = new EmptyTileInfoPanel((ITile) arg);
			}
			return emptyTileInfoPanel;
			
		} else if (panel == (Panels.SELECTEDBUILDINGPANEL)) {
			if (selectedBuildingPanel == null) {
				selectedBuildingPanel = new SelectedBuildingPanel((IBuilding) arg);
			}
			return selectedBuildingPanel;
			
		} else if (panel == (Panels.TROOPSSELECTEDPANEL)) {
			if (troopsSelectedPanel == null) {
				troopsSelectedPanel = new SelectedTroopsPanel((ArrayList<ITroop>) arg);
			}
			return troopsSelectedPanel;		
			
		} else if (panel == (Panels.BUILDPANEL)) {
			if (buildPanel == null) {
				buildPanel = new BuildPanel((ITile) arg);
			}
			return buildPanel;
		} else if (panel == (Panels.TROOPPANEL)) {
			return new TroopPanel((ITroop) arg);	
		}
		
		return null;
	}
}
